function psnr = cal_psnr(img1, img2);
% Calculating PSNR in dB.

[row, col] = size(img1);
img2 = imresize(img2, [row col]);

B = 8;
MAX = 2 ^ B - 1;
MES = sum(sum((img1 - img2) .^ 2)) / (row * col);
% psnr = MAX / sqrt(MES); 
psnr = 20 * log10(MAX / sqrt(MES)); 
return;